package org.pi.common.dir

object FileSelector {
	def selectFile(owner: javax.swing.JComponent) : java.io.File = selectFile(owner,"default")
	def selectFile(owner: javax.swing.JComponent, id: String) : java.io.File = {
		val prefs = java.util.prefs.Preferences.userNodeForPackage( owner.getClass() );
		val fc = new javax.swing.JFileChooser();
		val curDir = System.getProperty("user.dir");
		println(curDir)
		fc.setCurrentDirectory(new java.io.File(curDir));
		val selFile = prefs.get("selectedFile/"+id, "")
		if (selFile != "")	fc.setSelectedFile( new java.io.File(selFile) );
		val returnVal = fc.showOpenDialog(owner);
		if (returnVal == javax.swing.JFileChooser.APPROVE_OPTION) {
			val file = fc.getSelectedFile();
			prefs.put("selectedFile/"+id,file.getAbsolutePath());
			file
		}
		else {
			throw new Error("no file choosen.");
		}
	}
}
